import axios from 'axios'
let baseUrl = 'http://api.ucmd.cn/renren-api'
function apiAxios (method, url, params) {
  return new Promise((resolve, reject) => {
    axios({
      method: method,
      url: baseUrl + url,
      ContentType: 'application/json;',
      data: method === 'POST' || method === 'PUT' ? params : null,
      params: method === 'GET' || method === 'DELETE' ? params : null
    }).then(res => {
      if (res.status === 200) {
        resolve(res.data)
      }
    })
  })
}

export default {
  get (url, params) {
    return apiAxios('GET', url, params)
  },
  post (url, params) {
    return apiAxios('POST', url, params)
  }
}
